/** @brief File containing the implementation of the base class for graphic
 * representation.
 *
 * This file contains the implementation of the base class defining the
 * interface of the visualisation classes.
 *
 * @file RepresentationBase.cpp
 * @author Johan "Solo" Luisier
 * @date 2013/03/25
 */
#include "RepresentationBase.hpp"

#include "Core/GridBase.hpp"

#include <QtCore/QDebug>
#include <QtCore/QPoint>

#include <QtSvg/QGraphicsSvgItem>

RepresentationBase::RepresentationBase( GridBase* grid, QObject* parent )
    : QGraphicsScene( parent )
    , GridModel( grid )
{
    connect( GridModel, SIGNAL( flipped( QPoint ) ), this, SLOT( updateCellView( QPoint ) ) );
}

RepresentationBase::~RepresentationBase()
{}

void RepresentationBase::updateCellView( const QPoint &coord )
{
    qDebug() << "Should flip cell at coordinates" << coord;

    if ( coord == QPoint( -1, -1 ) )
        return;

    QGraphicsItem* cellSvg = CellTiles[ coord.x() + coord.y() * GridModel -> height()  ];

    qDebug() << "svg item state before:" << cellSvg -> isVisible();

    if ( cellSvg -> isVisible() )
        cellSvg -> hide();
    else
        cellSvg -> show();

    qDebug() << "svg item state after:" << cellSvg -> isVisible();
}
